//
//  SwapViewViewController.m
//  SwapView
//
//  Created by KaiKai on 11-7-17.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "SwapViewViewController.h"

@implementation SwapViewViewController

- (void)dealloc
{
	[landscape release];
	[portrait release];
	[landscapeBarButton release];
	[landscapeFooButton release];
	[portraitBarButton release];
	[portraitFooButton release];
	
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
//    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
	return YES;
}

- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
	if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
	{
		self.view = portrait;
		self.view.transform = CGAffineTransformIdentity;
		self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
		self.view.bounds = CGRectMake(0, 0, 300, 480);
	}
	else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
	{
		self.view = landscape;
		self.view.transform = CGAffineTransformIdentity;
		self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
		self.view.bounds = CGRectMake(0, 0, 460, 320);
	}
	else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
	{
		self.view = portrait;
		self.view.transform = CGAffineTransformIdentity;
		self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
		self.view.bounds = CGRectMake(0, 0, 300, 480);
	}
	else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
	{
		self.view = landscape;
		self.view.transform = CGAffineTransformIdentity;
		self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
		self.view.bounds = CGRectMake(0, 0, 460, 320);
	}
}

- (IBAction)buttonPressed:(id)sender
{
	if (sender == portraitFooButton || sender == landscapeFooButton)
	{
		portraitFooButton.hidden = YES;
		landscapeFooButton.hidden = YES;
	}
	else
	{
		portraitBarButton.hidden = YES;
		landscapeBarButton.hidden = YES;
	}
}

@end
